package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/14 11:21
 * @description
 */
public class Code783 {
    private List<Integer> list = new ArrayList<>();

    public int minDiffInBST(TreeNode root) {
        getMin(root);
        int min = 999;
        Collections.sort(list);
        for (int i = 1; i < list.size(); i++) {
            min = Math.min(min, list.get(i) - list.get(i - 1));
        }
        return min;
    }

    private void getMin(TreeNode node) {
        if (node != null) {
            list.add(node.val);
            getMin(node.left);
            getMin(node.right);
        }
    }
}
